/******************************************************************************
 * @File name   :      LinkageSelectTagController.java
 *
 * @Author      :      chen shixiang
 *
 * @Date        :      2011-4-20
 *
 * @Copyright Notice: 
 * Copyright (c) 2014 DMS, Inc. All  Rights Reserved.
 * This software is published under the terms of the DMS Software
 * License version 1.0, a copy of which has been included with this
 * distribution in the LICENSE.txt file.
 * 
 * 
 * ----------------------------------------------------------------------------
 * Date                   Who         Version        Comments
 * 2011-4-20 上午11:19:45        chen shixiang     1.0            Initial Version
 *****************************************************************************/
package com.cap.bts.framework.controller.jsptag;

import java.util.ArrayList;
import java.util.List;

import com.cap.bts.framework.controller.constant.MappingConstant;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.cap.bts.framework.codemapping.domain.CodeInfo;
import com.cap.bts.framework.codemapping.service.ICodeMapping;
import com.cap.bts.framework.common.exception.AppException;

/**
 *
 */
@Controller
public class LinkageSelectTagController {
    
    @Autowired
    private ICodeMapping codeMapping;
    private static Logger logger = Logger.getLogger(LinkageSelectTagController.class);
    

    /**
     * 查询code info
     * @Date        :      2011-12-7
     * @param parentCode
     * @return
     */
    @RequestMapping(value = "/linkageselect/{parentCode}", method = RequestMethod.GET)
    public @ResponseBody List<CodeInfo> getCodeInfoByParentCode(@PathVariable("parentCode") String parentCode) {
	
	List<CodeInfo> l = new ArrayList<CodeInfo>();
	try {
	    if(parentCode != null && Integer.valueOf(parentCode).equals(MappingConstant.defaultCompetitorFactoryParentId)){
	    	parentCode  = MappingConstant.getCompetitorFactoryActualParentId();
	    }
	    //l = codeMapping.getCodeInfoByParentCode(codeMapping.getCodeInfoDtoById(Long.parseLong(parentCode)).getCode());
	    l = codeMapping.getAvailableCodeInfoByParentCode(codeMapping.getCodeInfoDtoById(Long.parseLong(parentCode)).getCode());
	    logger.info("request one time!");
	} catch (AppException e) {
	    e.printStackTrace();
	}
	return l;
    }
    /**
     * 主数据父子级联动选择Tag使用样例
     * @Date        :      2011-12-7
     * @return
     */
    @RequestMapping(value = "/ls", method = RequestMethod.GET)
    public ModelAndView getJspPage() {
	return new ModelAndView("ls_example");
    }
    
    /**
     * @Date        :      2011-4-20
     *
     * @return the codeMapping
     */
    public ICodeMapping getCodeMapping() {
        return codeMapping;
    }

    /**
     * @Date        :      2011-4-20
     *
     * @param codeMapping the codeMapping to set
     */
    public void setCodeMapping(ICodeMapping codeMapping) {
        this.codeMapping = codeMapping;
    }
}
